﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Data;
using CE.Database;

/// <summary>
/// Summary description for BenefitScaleDB
/// </summary>
/// 
namespace CE.Provider
{
    public class BenefitScaleDB
    {
        public BenefitScaleDB()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public Int64 Insert(BenefitScale benefitscale)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "sprocPABenefitScaleInsertUpdateSingleItem";

            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@PABenefitId", benefitscale.PABenefitId);
            _sPara.Add("@PAInsId", benefitscale.PAInsId);
            _sPara.Add("@PACompanyId", benefitscale.PACompanyId);
            _sPara.Add("@PolicyType", benefitscale.PolicyType);
            _sPara.Add("@DeathPerDisable", benefitscale.DeathPerDisable);
            _sPara.Add("@LossLimb", benefitscale.LossLimb);
            _sPara.Add("@LossTwoLimbs", benefitscale.LossTwoLimbs);
            _sPara.Add("@LossOneEye", benefitscale.LossOneEye);
            _sPara.Add("@LossBothEye", benefitscale.LossBothEye);
            _sPara.Add("@LossOneEar", benefitscale.LossOneEar);
            _sPara.Add("@LossBothEar", benefitscale.LossBothEar);
            _sPara.Add("@LossSpeech", benefitscale.LossSpeech);
            _sPara.Add("@TotParalysis", benefitscale.TotParalysis);
            _sPara.Add("@PerBedridden", benefitscale.PerBedridden);
            _sPara.Add("@LossFinRH", benefitscale.LossFinRH);
            _sPara.Add("@LossFinLH", benefitscale.LossFinLH);
            _sPara.Add("@LossFinOneHand", benefitscale.LossFinOneHand);
            _sPara.Add("@LossThumbBothPhalanges", benefitscale.LossThumbBothPhalanges);
            _sPara.Add("@LossThumbRPhalanx", benefitscale.LossThumbRPhalanx);
            _sPara.Add("@LossThumbLPhalanx", benefitscale.LossThumbLPhalanx);
            _sPara.Add("@LossIndexFinThreePhalanges", benefitscale.LossIndexFinThreePhalanges);
            _sPara.Add("@LossIndexFinTwoPhalanges", benefitscale.LossIndexFinTwoPhalanges);
            _sPara.Add("@LossIndexFinOnePhalanx", benefitscale.LossIndexFinOnePhalanx);
            _sPara.Add("@LossMidFinThreePhalanges", benefitscale.LossMidFinThreePhalanges);
            _sPara.Add("@LossMidFinTwoPhalanges", benefitscale.LossMidFinTwoPhalanges);
            _sPara.Add("@LossMidFinOnePhalanx", benefitscale.LossMidFinOnePhalanx);
            _sPara.Add("@LossRingFinThreePhalanges", benefitscale.LossRingFinThreePhalanges);
            _sPara.Add("@LossRingFinTwoPhalanges", benefitscale.LossRingFinTwoPhalanges);
            _sPara.Add("@LossRingFinOnePhalanx", benefitscale.LossRingFinOnePhalanx);
            _sPara.Add("@LossLitFinThreePhalanges", benefitscale.LossLitFinThreePhalanges);
            _sPara.Add("@LossLitFinTwoPhalanges", benefitscale.LossLitFinTwoPhalanges);
            _sPara.Add("@LossLitFinOnePhalanx", benefitscale.LossLitFinOnePhalanx);
            _sPara.Add("@LossAllToesOneFoot", benefitscale.LossAllToesOneFoot);
            _sPara.Add("@LossGToeTwoPhalanges", benefitscale.LossGToeTwoPhalanges);
            _sPara.Add("@LossGToeOnePhalanx", benefitscale.LossGToeOnePhalanx);
            _sPara.Add("@LossOToeOneMorePhalanges", benefitscale.LossOToeOneMorePhalanges);
            _sPara.Add("@ThirdDegreeBurn", benefitscale.ThirdDegreeBurn);
            _sPara.Add("@Status", benefitscale.Status);
            _sPara.Add("@RefCEUserId", benefitscale.RefCEUserId);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public BenefitScale GetBenefitScale(Int64 PACompanyId, Int64 PAInsId)
        {
            BenefitScale _benefitscale = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocPABenefitScaleSelectSingleItem";

            SortedList _spara = new SortedList();
            _spara.Add("@PACompanyId", PACompanyId);
            //_spara.Add("@PABenefitId", PABenefitId);
            _spara.Add("@PAInsId", PAInsId);

            DataTable _dt = _db.GetDataTableBySP(_spName, _spara);
            if (_dt != null)
            {
                _benefitscale = new BenefitScale();
                if (_dt.Rows.Count > 0)
                {
                    _benefitscale = FillDataRecord(_dt);
                }
            }
            return _benefitscale;
        }

        private BenefitScale FillDataRecord(DataTable myDataTable)
        {
            BenefitScale myBenefitScale = new BenefitScale();
            myBenefitScale.PABenefitId = Convert.ToInt64(myDataTable.Rows[0]["PABenefitId"].ToString());
            myBenefitScale.PAInsId = Convert.ToInt64(myDataTable.Rows[0]["PAInsId"].ToString());
            myBenefitScale.PACompanyId = Convert.ToInt64(myDataTable.Rows[0]["PACompanyId"].ToString());
            myBenefitScale.PlanName = myDataTable.Rows[0]["PlanName"].ToString();
            myBenefitScale.PolicyType = myDataTable.Rows[0]["PolicyType"].ToString();
            myBenefitScale.DeathPerDisable = Convert.ToInt32(myDataTable.Rows[0]["DeathPerDisable"].ToString());
            myBenefitScale.LossLimb = Convert.ToInt32(myDataTable.Rows[0]["LossLimb"].ToString());
            myBenefitScale.LossTwoLimbs = Convert.ToInt32(myDataTable.Rows[0]["LossTwoLimbs"].ToString());
            myBenefitScale.LossOneEye = Convert.ToInt32(myDataTable.Rows[0]["LossOneEye"].ToString());
            myBenefitScale.LossBothEye = Convert.ToInt32(myDataTable.Rows[0]["LossBothEye"].ToString());
            myBenefitScale.LossOneEar = Convert.ToInt32(myDataTable.Rows[0]["LossOneEar"].ToString());
            myBenefitScale.LossBothEar = Convert.ToInt32(myDataTable.Rows[0]["LossBothEar"].ToString());
            myBenefitScale.LossSpeech = Convert.ToInt32(myDataTable.Rows[0]["LossSpeech"].ToString());
            myBenefitScale.TotParalysis = Convert.ToInt32(myDataTable.Rows[0]["TotParalysis"].ToString());
            myBenefitScale.PerBedridden = Convert.ToInt32(myDataTable.Rows[0]["PerBedridden"].ToString());
            myBenefitScale.LossFinRH = Convert.ToInt32(myDataTable.Rows[0]["LossFinRH"].ToString());
            myBenefitScale.LossFinLH = Convert.ToInt32(myDataTable.Rows[0]["LossFinLH"].ToString());
            myBenefitScale.LossFinOneHand = Convert.ToInt32(myDataTable.Rows[0]["LossFinOneHand"].ToString());
            myBenefitScale.LossThumbBothPhalanges = Convert.ToInt32(myDataTable.Rows[0]["LossThumbBothPhalanges"].ToString());
            myBenefitScale.LossThumbRPhalanx = Convert.ToInt32(myDataTable.Rows[0]["LossThumbRPhalanx"].ToString());
            myBenefitScale.LossThumbLPhalanx = Convert.ToInt32(myDataTable.Rows[0]["LossThumbLPhalanx"].ToString());
            myBenefitScale.LossIndexFinThreePhalanges = Convert.ToInt32(myDataTable.Rows[0]["LossIndexFinThreePhalanges"].ToString());
            myBenefitScale.LossIndexFinTwoPhalanges = Convert.ToInt32(myDataTable.Rows[0]["LossIndexFinTwoPhalanges"].ToString());
            myBenefitScale.LossIndexFinOnePhalanx = Convert.ToInt32(myDataTable.Rows[0]["LossIndexFinOnePhalanx"].ToString());
            myBenefitScale.LossMidFinThreePhalanges = Convert.ToInt32(myDataTable.Rows[0]["LossMidFinThreePhalanges"].ToString());
            myBenefitScale.LossMidFinTwoPhalanges = Convert.ToInt32(myDataTable.Rows[0]["LossMidFinTwoPhalanges"].ToString());
            myBenefitScale.LossMidFinOnePhalanx = Convert.ToInt32(myDataTable.Rows[0]["LossMidFinOnePhalanx"].ToString());
            myBenefitScale.LossRingFinThreePhalanges = Convert.ToInt32(myDataTable.Rows[0]["LossRingFinThreePhalanges"].ToString());
            myBenefitScale.LossRingFinTwoPhalanges = Convert.ToInt32(myDataTable.Rows[0]["LossRingFinTwoPhalanges"].ToString());
            myBenefitScale.LossRingFinOnePhalanx = Convert.ToInt32(myDataTable.Rows[0]["LossRingFinOnePhalanx"].ToString());
            myBenefitScale.LossLitFinThreePhalanges = Convert.ToInt32(myDataTable.Rows[0]["LossLitFinThreePhalanges"].ToString());
            myBenefitScale.LossLitFinTwoPhalanges = Convert.ToInt32(myDataTable.Rows[0]["LossLitFinTwoPhalanges"].ToString());
            myBenefitScale.LossLitFinOnePhalanx = Convert.ToInt32(myDataTable.Rows[0]["LossLitFinOnePhalanx"].ToString());
            myBenefitScale.LossAllToesOneFoot = Convert.ToInt32(myDataTable.Rows[0]["LossAllToesOneFoot"].ToString());
            myBenefitScale.LossGToeTwoPhalanges = Convert.ToInt32(myDataTable.Rows[0]["LossGToeTwoPhalanges"].ToString());
            myBenefitScale.LossGToeOnePhalanx = Convert.ToInt32(myDataTable.Rows[0]["LossGToeOnePhalanx"].ToString());
            myBenefitScale.LossOToeOneMorePhalanges = Convert.ToInt32(myDataTable.Rows[0]["LossOToeOneMorePhalanges"].ToString());
            myBenefitScale.ThirdDegreeBurn = myDataTable.Rows[0]["ThirdDegreeBurn"].ToString();
            myBenefitScale.Status = Convert.ToBoolean(myDataTable.Rows[0]["Status"].ToString());
            myBenefitScale.RefCEUserId = Convert.ToInt64(myDataTable.Rows[0]["RefCEUserId"].ToString());
            return myBenefitScale;
        }

        public DataTable GetBenefitScaleList(Int64 PACompanyId, string PlanName)
        {
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocPABenefitScaleSelectItemList";

            SortedList _spara = new SortedList();
            _spara.Add("@PACompanyId", PACompanyId);
            _spara.Add("@PlanName", PlanName);

            DataTable _dt = _db.GetDataTableBySP(_spName, _spara);

            return _dt;

        }

    }
}